home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume3 / conquer / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-01-23  |  52.4 KB

  1. Path: uunet!seismo!sundc!pitstop!sun!amdcad!ames!ll-xn!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v03i071:  conquer - version 2 of the renamed conquest adventure game, Part02/06
  5. Message-ID: <2105@tekred.TEK.COM>
  6. Date: 22 Jan 88 21:33:26 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 1823
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: ihnp4!mhuxd!smile (Ed Barlow)
  12. Comp.sources.games: Volume 3, Issue 71
  13. Archive-name: conquer/Part02
  14.  
  15. #! /bin/sh
  16.  
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 2 (of 6)."
  23. # Contents:  cexecute.c makeworld.c npc.c
  24. # Wrapped by billr@tekred on Fri Jan 22 13:27:00 1988
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f cexecute.c -a "${1}" != "-c" ; then 
  27.   echo shar: Will not over-write existing file \"cexecute.c\"
  28. else
  29. echo shar: Extracting \"cexecute.c\" \(3670 characters\)
  30. sed "s/^X//" >cexecute.c <<'END_OF_cexecute.c'
  31. X/*conquer is copyrighted 1986 by Ed Barlow.
  32. X *  I spent a long time writing this code & I hope that you respect this.  
  33. X *  I give permission to alter the code, but not to copy or redistribute
  34. X *  it without my explicit permission.  If you alter the code, 
  35. X *  please document changes and send me a copy, so all can have it.  
  36. X *  This code, to the best of my knowledge works well,  but it is my first
  37. X *  'C' program and should be treated as such.  I disclaim any
  38. X *  responsibility for the codes actions (use at your own risk).  I guess
  39. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  40. X *                                                Ed
  41. X */
  42. X
  43. X/*EXECUTE THE PROGRAM*/
  44. X#include "header.h"
  45. X#include "data.h"
  46. Xextern short country;
  47. X
  48. Xexecute()
  49. X{
  50. X    FILE *fp, *fopen();
  51. X    int cmd,savectry;
  52. X    char comment[20];
  53. X    char temp[10];
  54. X    long longvar,long2var;
  55. X    int armynum;
  56. X    short int x,y;
  57. X    int execed=0;
  58. X    int done=0;
  59. X    char line[80];
  60. X
  61. X    /*execute in random order*/
  62. X    /*open exefile file*/
  63. X    sprintf(line,"%s%d",exefile,country);
  64. X    if ((fp=fopen(line,"r"))==NULL) {
  65. X        /*THIS MEANS THAT THE NATION HAS NOT MOVED YET*/
  66. X        return(0);
  67. X    }
  68. X    savectry=country;
  69. X
  70. X    /*read in file*/
  71. X    if(fgets(line,80,fp)==NULL) done=1;
  72. X    while(done==0) {
  73. X        /*read and parse a new line*/
  74. X        /*CODE IF YOU USE LONG VAR IS L_*/
  75. X          if( line[0] == 'L' && line[1] == '_' ) {
  76. X              sscanf(line,"%s %d %hd %ld %ld %hd %s",
  77. X                  temp,&cmd,&country,&longvar,&long2var,&y,comment);
  78. X          } else {
  79. X              sscanf(line,"%s %d %hd %d %hd %hd %s",
  80. X                  temp,&cmd,&country,&armynum,&x,&y,comment);
  81. X          }
  82. X        execed=1;
  83. X        switch(cmd){
  84. X        case XASTAT:        /*Aadjstat*/
  85. X            if((x>0)&&(x<6))  ASTAT=x;
  86. X            break;
  87. X        case XAMEN:    /*Aadjmen*/
  88. X            armynum= (int) longvar;
  89. X            ASOLD= (int) long2var;
  90. X            break;
  91. X        case XALOC:    /*Aadjloc*/
  92. X            AXLOC=x;
  93. X            AYLOC=y;
  94. X            break;
  95. X        case XNLOC: /*nadjloc*/
  96. X            ntn[country].nvy[armynum].xloc=x;
  97. X            ntn[country].nvy[armynum].yloc=y;
  98. X            break;
  99. X        case XNASHP: /*nadjshp*/
  100. X            ntn[country].nvy[armynum].merchant=x;
  101. X            ntn[country].nvy[armynum].warships=y;
  102. X            break;
  103. X        case XECNAME:    /*Nadjname*/
  104. X            strcpy(ntn[country].name,comment);
  105. X            break;
  106. X        case XECPAS:    /*Nadjpas*/
  107. X            strncpy(ntn[country].passwd,comment,PASSLTH);
  108. X            break;
  109. X        case XECMARK:    /*Echgmark*/
  110. X            ntn[country].mark=comment[0];
  111. X            break;
  112. X        case XSADES:    /*Sadjdes*/
  113. X            if((sct[x][y].owner==country)||(country==0)) {
  114. X                sct[x][y].designation=comment[0];
  115. X            }
  116. X            if(sct[x][y].designation==DCAPITOL){
  117. X                ntn[country].capx=x;
  118. X                ntn[country].capy=y;
  119. X            }
  120. X            break;
  121. X        case XSACIV:    /*Sadjciv*/
  122. X            sct[x][y].people=armynum;
  123. X            break;
  124. X        case XSIFORT:    /*Sincfort*/
  125. X            sct[x][y].fortress++;
  126. X            break;
  127. X        case XNAGOLD:    /*Nadjgold:*/
  128. X            ntn[country].tgold = longvar;
  129. X            break;
  130. X        case XAMOV:
  131. X            AMOVE=x;
  132. X            break;
  133. X        case XNMOV:
  134. X            ntn[country].nvy[armynum].smove=x;
  135. X            break;
  136. X        case XSAOWN:
  137. X            sct[x][y].owner=country;
  138. X            break;
  139. X        case EDADJ:
  140. X            ntn[country].dstatus[armynum]=x;
  141. X            break;
  142. X        case XNARGOLD:
  143. X            ntn[country].jewels = longvar;
  144. X            break;
  145. X        case XNAIRON:
  146. X            ntn[country].tiron = longvar;
  147. X            break;
  148. X        case INCAPLUS:
  149. X            ntn[country].aplus++;
  150. X            break;
  151. X        case INCDPLUS:
  152. X            ntn[country].dplus++;
  153. X            break;
  154. X        case DESTRY:
  155. X            sct[ntn[armynum].capx][ntn[armynum].capy].owner=savectry;
  156. X            country=armynum;
  157. X            destroy();
  158. X            country=savectry;
  159. X            break;
  160. X        case CHG_MGK:
  161. X            ntn[country].powers|=long2var;
  162. X            if(ntn[country].powers!=longvar){
  163. X            printf("\nERROR ON MAGIC READ %ld != %d (or of %d)",longvar,ntn[country].powers,long2var);
  164. X            getchar();
  165. X            }
  166. X            exenewmgk(long2var);
  167. X            long2var=0;
  168. X        }
  169. X        if(fgets(line,80,fp)==NULL) done=1;
  170. X    }
  171. X    fclose(fp);
  172. X    /*return 1 if it did something*/
  173. X    country=savectry;
  174. X    if(execed==1) return(1);
  175. X    else return(0);
  176. X}
  177. X
  178. END_OF_cexecute.c
  179. if test 3670 -ne `wc -c <cexecute.c`; then
  180.     echo shar: \"cexecute.c\" unpacked with wrong size!
  181. fi
  182. # end of overwriting check
  183. fi
  184. if test -f makeworld.c -a "${1}" != "-c" ; then 
  185.   echo shar: Will not over-write existing file \"makeworld.c\"
  186. else
  187. echo shar: Extracting \"makeworld.c\" \(21365 characters\)
  188. sed "s/^X//" >makeworld.c <<'END_OF_makeworld.c'
  189. X/*conquer is copyrighted 1986 by Ed Barlow.
  190. X *  I spent a long time writing this code & I hope that you respect this.  
  191. X *  I give permission to alter the code, but not to copy or redistribute
  192. X *  it without my explicit permission.  If you alter the code, 
  193. X *  please document changes and send me a copy, so all can have it.  
  194. X *  This code, to the best of my knowledge works well,  but it is my first
  195. X *  'C' program and should be treated as such.  I disclaim any
  196. X *  responsibility for the codes actions (use at your own risk).  I guess
  197. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  198. X *                                                Ed
  199. X */
  200. X
  201. X/*Create a world*/
  202. X
  203. X/*DEFINE TEMPORARY VARIABLES FROM MAKEFILE*/
  204. X#include <ctype.h>
  205. X#include <stdio.h>
  206. X#include "header.h"
  207. X#include "data.h"
  208. X
  209. X#define HALF 2
  210. X#define LAND 3
  211. X
  212. Xextern short country;
  213. Xint area_map[MAXX][MAXY];/*Value Map of Areas*/
  214. Xint type[MAPX][MAPY];
  215. X
  216. Xmakeworld()
  217. X{
  218. X    register int i,j;
  219. X    register int x,y;
  220. X    int n; /*count used in string searches*/
  221. X    float avvalue; /*Average water tvalue of sectors*/
  222. X    int number[5]; /*Number of sectors with type=[0-4]*/
  223. X    char passwd[12];
  224. X    int alloc = NUMAREAS * 2;/*Value Allocated*/
  225. X    int place[MAXX][MAXY] ;/*Temporary matrix to see if an area is placed*/
  226. X    int X, Y;
  227. X    int X1,Y1;
  228. X    int X2,Y2;
  229. X    int valid;
  230. X    int nranges;
  231. X    int rnd;
  232. X    int tempfd;
  233. X    char newstring[40];
  234. X
  235. X    /*abort if datafile currently exists*/
  236. X    if(tempfd=open(datafile,0)!=-1) {
  237. X        printf("ABORTING: File %s exists\n",datafile);
  238. X        printf("\tthis means that a game is in progress. To proceed, you must remove \n");
  239. X        printf("\tthe existing data file. This will, of course, destroy that game.\n\n");
  240. X        exit(1);
  241. X    }
  242. X    printf("\n**********************WELCOME TO CONQUER**********************");
  243. X    printf("\nThe world will now be created...Your super user login will be 'god'.");
  244. X    printf("\nNon player countries will be read from data stored in the nations file"); 
  245. X    printf("\n& will have the same password as god (about to be entered). Add player");
  246. X    printf("\nnations with the command <conquer -a>.  Have fun!!!\n");
  247. X    printf("\nRemember to check the world out before playing to make sure");
  248. X    printf("\nno nations are in bad positions (surrounded by water... )");
  249. X    printf("******************************************************************\n\n");
  250. X
  251. X    printf("First, we must zero extraneous files from prior games\n");
  252. X    sprintf(newstring,"rm %s*\n",exefile);
  253. X    printf("\t%s",newstring);
  254. X    system(newstring);
  255. X    sprintf(newstring,"rm %s*\n",msgfile);
  256. X    printf("\t%s",newstring);
  257. X    system(newstring);
  258. X    sprintf(newstring,"> %s",newsfile);
  259. X    printf("\t%s\n",newstring);
  260. X    system(newstring);
  261. X    printf("OK This has been done, Now to set up a new world\n\n");
  262. X
  263. X    printf("please enter new super user password (remember this!):");
  264. X    scanf("%s",passwd);
  265. X    getchar();
  266. X    printf("please reenter password:");
  267. X    scanf("%s",ntn[0].passwd);
  268. X    getchar();
  269. X    if((strlen(ntn[0].passwd)<2)
  270. X    ||(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) {
  271. X        printf("\ninvalid super user password\n");
  272. X        exit(1);
  273. X    }
  274. X    strncpy(ntn[0].passwd,crypt(passwd,SALT),PASSLTH);
  275. X
  276. X    printf("\n\ncreating world\n");
  277. X    /*initialize variables */
  278. X    avvalue = (((float) PWATER/25.0)); /*Average water tvalue of sectors*/
  279. X    for(i=0;i<MAXX;i++) for(j=0;j<MAXY;j++) {
  280. X        place[i][j]=0;
  281. X        area_map[i][j]=0;
  282. X    }
  283. X    for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++) sct[i][j].vegetation=NONE;
  284. X
  285. X    for(i=0;i<5;i++) number[i] = NUMAREAS/5;  /*areas with type=[i]*/
  286. X    number[2]=NUMAREAS - 4*number[0]; /*correct for roundoff*/
  287. X
  288. X    /*determine # of area types to areas*/
  289. X    for(i=0;i<250;i++) {
  290. X        if((avvalue*NUMAREAS)>alloc) {
  291. X            /*have not allocated high enough so Allocate more */
  292. X            x = rand()%4;   /*0 to 3*/
  293. X            if(number[x]>0) {
  294. X                number[x] = number[x] - 1;
  295. X                number[x+1] = number[x+1] + 1;
  296. X                alloc = alloc + 1;
  297. X            }
  298. X        }
  299. X        else    {
  300. X            /*have allocated too much  Allocate less */
  301. X            x = (rand()%4) +1; /*1 to 4*/
  302. X            if(number[x]>0) {
  303. X                number[x] = number[x] - 1;
  304. X                number[x-1] = number[x-1] + 1;
  305. X                alloc = alloc - 1;
  306. X            }
  307. X        }
  308. X    }
  309. X
  310. X    i=0;
  311. X    while((number[4]>0)&&(i<500)) {
  312. X        i++;
  313. X        /*place a full land sector anywhere but on edge*/
  314. X        X = ((rand()%(MAXX-2))+1); /*1 to MAXX-2)*/
  315. X        Y = ((rand()%(MAXY-2))+1); /*1 to MAXY-2)*/
  316. X        if(place[X][Y] == 0) {
  317. X            place[X][Y]=1;
  318. X            area_map[X][Y]=4;
  319. X            number[4]=number[4] - 1;
  320. X            /*place surrounding sectors*/
  321. X            if(place[X+1][Y] == 0) {
  322. X                rnd = rand()%100 + 1; /*1 to 100*/
  323. X                if((rnd<25) && (number[4]>0)) {
  324. X                    area_map[X+1][Y]=4;
  325. X                    number[4]=number[4]-1;
  326. X                    place[X+1][Y]=1;
  327. X                }
  328. X                if(rnd>25 && number[3]>0) {
  329. X                    area_map[X+1][Y]=3;
  330. X                    number[3]=number[3]-1;
  331. X                    place[X+1][Y]=1;
  332. X                }
  333. X            }
  334. X            if(place[X-1][Y] == 0) {
  335. X                rnd = rand()%100 + 1 ; /*(1 to 100)*/
  336. X                if(rnd<25 && number[4]>0) {
  337. X                    area_map[X-1][Y]=4;
  338. X                    number[4]=number[4]-1;
  339. X                    place[X-1][Y]=1;
  340. X                }
  341. X                if(rnd>25 && number[3]>0) {
  342. X                    area_map[X-1][Y]=3;
  343. X                    number[3]=number[3]-1;
  344. X                    place[X-1][Y]=1;
  345. X                }
  346. X            }
  347. X            if(place[X][Y+1] == 0) {
  348. X                rnd = rand()%100 + 1 ; /*(1 to 100)*/
  349. X                if(rnd<25 && number[4]>0) {
  350. X                    area_map[X][Y+1]=4;
  351. X                    number[4]=number[4]-1;
  352. X                    place[X][Y+1]=1;
  353. X                }
  354. X                if(rnd>25 && number[3]>0) {
  355. X                    area_map[X][Y+1]=3;
  356. X                    number[3]=number[3]-1;
  357. X                    place[X][Y+1]=1;
  358. X                }
  359. X            }
  360. X            if(place[X][Y-1] == 0) {
  361. X                rnd = rand()%100 + 1 ; /*(1 to 100)*/
  362. X                if(rnd<25 && number[4]>0) {
  363. X                    area_map[X][Y-1]=4;
  364. X                    number[4]=number[4]-1;
  365. X                    place[X][Y-1]=1;
  366. X                }
  367. X                if(rnd>25 && number[3]>0) {
  368. X                    area_map[X][Y-1]=3;
  369. X                    number[3]=number[3]-1;
  370. X                    place[X][Y-1]=1;
  371. X                }
  372. X            }
  373. X        }
  374. X    }
  375. X
  376. X    /* place all other areas*/
  377. X    for(X=0;X<MAXX;X++) for(Y=0;Y<MAXY;Y++) {
  378. X        while(place[X][Y] == 0) {
  379. X            rnd = rand()%5; /*(0 to 4)*/
  380. X            if(number[rnd]>0) {
  381. X                area_map[X][Y]=rnd;
  382. X                number[rnd]=number[rnd]-1;
  383. X                place[X][Y]=1;
  384. X            }
  385. X        }
  386. X    }
  387. X
  388. X    /*ALL AREAS PLACED, NOW DETERMINE SECTOR TYPE
  389. X *fill in each area with sectors
  390. X *      1)   water
  391. X *      2)   water with major islands (25% land)
  392. X *      3)   50/50 water/land 
  393. X *      4)   land with major water (75% Land)
  394. X *      5)   land 
  395. X */
  396. X    for(Y=0;Y<MAXY;Y++) for(X=0;X<MAXX;X++) {
  397. X        /*fill in edges*/
  398. X        fill_edge(X,Y);
  399. X        /*fill in center*/
  400. X        for(i=1;i<7;i++) {
  401. X            for(j=1;j<7;j++) switch(area_map[X][Y]){
  402. X
  403. X            case 0:
  404. X                if((rand()%100) < 95) type[X*8+i][Y*8+j]=WATER;
  405. X                else type[X*8+i][Y*8+j]=HALF;
  406. X                break;
  407. X            case 1:
  408. X                if(rand()%2 == 0) type[X*8+i][Y*8+j]=WATER;
  409. X                else type[X*8+i][Y*8+j]=HALF;
  410. X                break;
  411. X            case 2:
  412. X                if (rand()%2 == 0) type[X*8+i][Y*8+j]=WATER;
  413. X                else type[X*8+i][Y*8+j]=LAND;
  414. X                break;
  415. X            case 3:
  416. X                if (rand()%2 == 0) type[X*8+i][Y*8+j]=LAND;
  417. X                else type[X*8+i][Y*8+j]=HALF;
  418. X                break;
  419. X            case 4:
  420. X                if ((rand()%100) < 95) type[X*8+i][Y*8+j]=LAND;
  421. X                else type[X*8+i][Y*8+j]=HALF;
  422. X                break;
  423. X            default:
  424. X                printf("ERROR");
  425. X            }
  426. X        }
  427. X    }
  428. X
  429. X    /*calculate all 50% areas*/
  430. X    for(X=0;X<MAPX;X++) for(Y=0;Y<MAPY;Y++) {
  431. X        if(type[X][Y] == HALF)
  432. X            if(rand()%2 == 0) {
  433. X                type[X][Y] = LAND;
  434. X            }
  435. X            else type[X][Y] = WATER;
  436. X    }
  437. X
  438. X
  439. X    /*Adjust world given sectors as land or sea, place vegetation, designation, 
  440. X and altitude */
  441. X
  442. X    for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++)
  443. X        if(type[i][j]==LAND) sct[i][j].altitude = CLEAR;
  444. X        else sct[i][j].altitude = WATER;
  445. X
  446. X    /*place mountain ranges */
  447. X
  448. X    nranges=(rand()%10+3)*avvalue;
  449. X    printf("%d mountain ranges to be placed",nranges);
  450. X
  451. X    while(nranges>0) {
  452. X        /*Place one range randomly*/
  453. X        X1 = rand()%(MAPX-6);
  454. X        Y1 = rand()%(MAPY-6);
  455. X        if((type[X1][Y1]==LAND)
  456. X        &&(type[X1+1][Y1+1]==LAND)
  457. X        &&(type[X1+1][Y1]==LAND)
  458. X        &&(type[X1][Y1+1]==LAND)
  459. X        &&(type[X1+2][Y1+2]==LAND)) {
  460. X            /*place second endpoint */
  461. X            valid = 0;
  462. X            i=0;
  463. X            nranges--;
  464. X            while((valid==0) && (i<500)) {
  465. X                i++;
  466. X                X2 = (rand()%7) + X1;
  467. X                Y2 = (rand()%7) + Y1;
  468. X                if(type[X2][Y2] == LAND) {
  469. X                    valid = 1;
  470. X                    /*fill in mountain range*/
  471. X                    for(x=X1;x<=X2;x++) {
  472. X                        if(X1<X2) y=((Y2-Y1)*(x-X1)/(X2-X1))+Y1;
  473. X                        else y=Y1;
  474. X                        if(type[x][y] == LAND)
  475. X                            if(rand()%100>80) sct[x][y].altitude=PEAK;
  476. X                            else sct[x][y].altitude=MOUNTAIN;
  477. X                        if((y < MAPY - 1) 
  478. X                        && type[x][y+1] == LAND) {
  479. X                            rnd=rand()%100+1;
  480. X                            if(rnd>90) sct[x][y+1].altitude=PEAK;
  481. X                            else if(rnd>50) sct[x][y+1].altitude=MOUNTAIN;
  482. X                            else if(rnd>20) sct[x][y+1].altitude=HILL;
  483. X                        }
  484. X                        if((y!=0)
  485. X                        && type[x][y-1] == LAND ) {
  486. X                            rnd=rand()%100+1;
  487. X                            if(rnd>90) sct[x][y-1].altitude=PEAK;
  488. X                            else if(rnd>50) sct[x][y-1].altitude=MOUNTAIN;
  489. X                            else if(rnd>20) sct[x][y-1].altitude=HILL;
  490. X                        }
  491. X                        if((y>=2)
  492. X                        &&(type[x][y-2] == LAND )) {
  493. X                            rnd=rand()%100+1;
  494. X                            if(rnd>90) sct[x][y-2].altitude=MOUNTAIN;
  495. X                            else if(rnd>50) sct[x][y-2].altitude=HILL;
  496. X                        }
  497. X                        if((y < MAPY - 2)
  498. X                        &&(type[x][y+2] == LAND )) {
  499. X                            rnd=rand()%100+1;
  500. X                            if(rnd>90) sct[x][y+2].altitude=MOUNTAIN;
  501. X                            else if(rnd>50) sct[x][y+2].altitude=HILL;
  502. X                        }
  503. X                    }
  504. X                }
  505. X            }
  506. X        }
  507. X    }
  508. X
  509. X    /*fill in random hills to work out,not to left of to water*/
  510. X    for(i=1;i<NUMAREAS*3;i++) {
  511. X        x = rand()%(MAPX-1);
  512. X        y = rand()%(MAPY-1);
  513. X        if((type[x][y]==LAND)&&(type[x+1][y]==LAND))
  514. X            sct[x][y].altitude=HILL;
  515. X    }
  516. X
  517. X    /*make sure no peak or mountain is next to water*/
  518. X    for(y=1;y<MAPY-1;y++) for(x=1;x<MAPX-1;x++)
  519. X        if((sct[x][y].altitude==PEAK)
  520. X        ||(sct[x][y].altitude==MOUNTAIN))
  521. X            for(i=0;i<=2;i++) for(j=0;j<=2;j++)
  522. X                if(sct[x+i-1][y+j-1].altitude==WATER)
  523. X                    sct[x][y].altitude=HILL;
  524. X
  525. X    /*FIGURE OUT SECTOR VEGETATION TYPE
  526. X *use sector.altitude, and sector to determine vegetation
  527. X *from water is distance from nearest water
  528. X */
  529. X
  530. X    /*char veg[]="VDW46973JSI~"*/
  531. X    /*char veg[]="VDWBLGWFJSI~"*/
  532. X
  533. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  534. X        if(type[x][y]==LAND)
  535. X        {
  536. X            sct[x][y].vegetation=(*(veg+3+rand()%5));
  537. X            /*if hill then decrement vegetation*/
  538. X            if(sct[x][y].altitude==HILL) {
  539. X                for(n=3;n<9;n++)
  540. X                    if(sct[x][y].vegetation==(*(veg+n)))
  541. X                        sct[x][y].vegetation=(*(veg+n-1));
  542. X                if(area_map[x/8][y/8]<=1) sct[x][y].vegetation=VOLCANO;
  543. X            }
  544. X            else if(sct[x][y].altitude==MOUNTAIN)
  545. X                if((rand()%6==4)&&((y>MAPY/2+8)||(y<MAPY/2-8)))
  546. X                    sct[x][y].vegetation=ICE;
  547. X                else sct[x][y].vegetation=(*(veg+2+rand()%3));
  548. X            else if(sct[x][y].altitude==PEAK)
  549. X                if((rand()%3==0)&&((y>MAPY/2+8)||(y<MAPY/2-8)))
  550. X                    sct[x][y].vegetation=ICE;
  551. X                else sct[x][y].vegetation=VOLCANO;
  552. X        }
  553. X
  554. X    /*REWORK POLEAR/EQUATORIAL sector.vegetation*/
  555. X    /*Determine which areas are North Pole and Equatorial*/
  556. X    /*char veg[]="VDW46973JSI~"*/
  557. X    /*char veg[]="VDWBLGWFJSI~"*/
  558. X    /*               012345678901*/
  559. X
  560. X    /*polar work*/
  561. X    for(x=0;x<MAPX;x++)
  562. X    {
  563. X        for(y=0;y<6;y++) if(type[x][y]==LAND)
  564. X        {
  565. X            if(rand()%4 == 0) sct[x][y].vegetation = ICE;
  566. X            else for(n=3;n<10;n++)
  567. X                if(sct[x][y].vegetation==(*(veg+n)))
  568. X                    sct[x][y].vegetation=(*(veg+(n-1)));
  569. X        }
  570. X        for(y=MAPY-7;y<MAPY;y++) if(type[x][y]==LAND)
  571. X        {
  572. X            if(rand()%4 == 0) sct[x][y].vegetation = ICE;
  573. X            else for(n=3;n<10;n++)
  574. X                if(sct[x][y].vegetation==(*(veg+n)) )
  575. X                    sct[x][y].vegetation=(*(veg+(n-1)));
  576. X        }
  577. X    }
  578. X
  579. X    /*insert equator*/
  580. X    for(y=(MAPY/2)-8;y<=(MAPY/2)+8;y++) for(x=0;x<MAPX;x++)
  581. X        if(type[x][y]==LAND)
  582. X            if(rand()%10 ==0) sct[x][y].vegetation=DESERT;
  583. X            /*increment vegetation if between Waste and Jungle*/
  584. X            else for(n=2;n<9;n++)
  585. X                if((sct[x][y].vegetation==(*(veg+n)))
  586. X                &&(sct[x][y].altitude==CLEAR)
  587. X                &&(rand()%4==0)) 
  588. X                sct[x][y].vegetation=(*(veg+(n+1)));
  589. X
  590. X    /*char veg[]="VDW46973JSI~"*/
  591. X    /*char veg[]="VDWBLGWFJSI~"*/
  592. X    /*               012345678901*/
  593. X
  594. X    for(y=((MAPY/2)-2);y<=((MAPY/2)+2);y++) for(x=0;x<MAPX;x++)
  595. X        if((type[x][y]==LAND)&&(sct[x][y].altitude==CLEAR))
  596. X            if(rand()%10 == 0) sct[x][y].vegetation=DESERT;
  597. X            else if(rand()%10 == 0) sct[x][y].vegetation=JUNGLE;
  598. X            else if(rand()%10 == 0) sct[x][y].vegetation=SWAMP;
  599. X            /*increment vegetation again, but only Waste to Light*/
  600. X            else for(n=2;n<4;n++)
  601. X                if(sct[x][y].vegetation==(*(veg+n)))
  602. X                    sct[x][y].vegetation=(*(veg+(n+1)));
  603. X
  604. X    /*expand swamps*/
  605. X    for(y=2;y<MAPY;y++) for(x=2;x<MAPX;x++)
  606. X        if(sct[x][y].vegetation==SWAMP)
  607. X            for(i=0;i<2;i++) for(j=0;j<2;j++)
  608. X                if((type[x-i][y-j]==LAND)&&((rand()%3)==0))
  609. X                    sct[x-i][y-j].vegetation=SWAMP;
  610. X    /*expand deserts*/
  611. X    for(y=2;y<MAPY;y++) for(x=2;x<MAPX;x++)
  612. X        if(sct[x][y].vegetation==DESERT)
  613. X            for(i=0;i<2;i++) for(j=0;j<2;j++)
  614. X                if((type[x-i][y-j]==LAND)&&((rand()%3)==0))
  615. X                    sct[x-i][y-j].vegetation=DESERT;
  616. X
  617. X    /*change all volcanos to peaks */
  618. X    for(y=1;y<MAPY;y++) for(x=1;x<MAPX;x++)
  619. X        if(sct[x][y].vegetation==VOLCANO) sct[x][y].altitude=PEAK;
  620. X
  621. X    /*make sure no desert is next to water*/
  622. X    for(y=1;y<MAPY-1;y++) for(x=1;x<MAPX-1;x++)
  623. X        if(sct[x][y].vegetation==DESERT)
  624. X            for(i=0;i<=2;i++) for(j=0;j<=2;j++)
  625. X                if(sct[x+i-1][y+j-1].altitude==WATER)
  626. X                    sct[x][y].vegetation=LT_VEG;
  627. X
  628. X    /*PLACE EACH SECTOR'S RAW MATERIALS */
  629. X
  630. X    printf("\nplacing raw materials\n");
  631. X    for(y=0;y<MAPY;y++) for(x=0;x<MAPX;x++) {
  632. X
  633. X        /*gold*/
  634. X        if(rand()%10==0) sct[x][y].gold=rand()%4+4;
  635. X        else if(rand()%4==0) sct[x][y].gold=rand()%4;
  636. X        else sct[x][y].gold=0;
  637. X
  638. X        /*iron*/
  639. X        if(rand()%10==0) sct[x][y].iron=rand()%4+4;
  640. X        else if(rand()%4==0) sct[x][y].iron=rand()%4;
  641. X        else sct[x][y].iron=0;
  642. X
  643. X        /*default designations*/
  644. X        sct[x][y].designation=sct[x][y].vegetation;
  645. X
  646. X        /*default owner is unowned*/
  647. X        sct[x][y].owner=0;
  648. X    }
  649. X    populate();
  650. X    close(tempfd);
  651. X    writedata();
  652. X}
  653. X
  654. X/*fill: subroutine to fill in a square edges with land or sea*/
  655. Xfill_edge(AX,AY)
  656. X{
  657. X/*      1)   water
  658. X *      2)   water with major islands (25% land)
  659. X *      3)   50/50 water/land 
  660. X *      4)   land with major water (75% Land)
  661. X *      5)   land 
  662. X */
  663. X    register int i;
  664. X    int edgearea, X0, Y0, X1, Y1, X2, Y2, X3, Y3, X4, Y4;
  665. X    int area;
  666. X
  667. X    X0=AX;
  668. X    Y0=AY;
  669. X    X1=X0-1;
  670. X    Y1=Y0;
  671. X    X2=X0+1;
  672. X    Y2=Y0;
  673. X    X3=X0;
  674. X    Y3=Y0-1;
  675. X    X4=X0;
  676. X    Y4=Y0+1;
  677. X
  678. X    /*NORMALIZE FOR EDGE OF WORLD*/
  679. X      if( X1 < 0 ) X1 = MAXX - 1;
  680. X      if( X2 >= MAXX ) X2 = 0;
  681. X      if( Y3 < 0 ) Y3 = MAXY - 1;
  682. X      if( Y4 >= MAXY ) Y4 = 0;
  683. X
  684. X    area=area_map[X0][Y0];
  685. X    /*fill in south*/
  686. X    edgearea=area_map[X4][Y4];
  687. X    if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+i][Y0*8+7] = LAND;
  688. X    else if((area + edgearea)>3) {
  689. X        for(i=0;i<8;i++)
  690. X            if(rand()%2 == 0) type[(X0*8)+i][Y0*8+7] = LAND;
  691. X            else type[(X0*8)+i][Y0*8+7] = WATER;
  692. X    }
  693. X    else for(i=0;i<8;i++) type[(X0*8)+i][Y0*8+7] = WATER;
  694. X    /*fill in east*/
  695. X    edgearea=area_map[X2][Y2];
  696. X    if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = LAND;
  697. X    else if((area + edgearea)>3) {
  698. X        for(i=0;i<8;i++)
  699. X            if(rand()%2==0) type[X0*8+7][Y0*8+i] = LAND;
  700. X            else type[X0*8+7][Y0*8+i] = WATER;
  701. X    }
  702. X    else for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = WATER;
  703. X    /*fill in west*/
  704. X    edgearea=area_map[X1][Y1];
  705. X    if(area + edgearea > 6) for(i=0;i<=7;i++) type[X0*8][Y0*8+i] = LAND;
  706. X    else if((area + edgearea)>3) {
  707. X        for(i=0;i<8 ;i++)
  708. X            if(rand()%2==0) type[X0*8][Y0*8+i] = LAND;
  709. X            else type[X0*8][Y0*8+i] = WATER;
  710. X    }
  711. X    else for(i=0;i<8 ;i++) type[X0*8][Y0*8+i] = WATER;
  712. X    /*fill in north*/
  713. X    edgearea=area_map[X3][Y3];
  714. X    if(area + edgearea > 6) for(i=0;i<8 ;i++) type[X0*8+i][Y0*8] = LAND;
  715. X    else if((area + edgearea)>3) {
  716. X        for(i=0;i<8 ;i++)
  717. X            if(rand()%2==0) type[(X0*8)+i][Y0*8] = LAND;
  718. X            else type[(X0*8)+i][Y0*8] = WATER;
  719. X    }
  720. X    else for(i=0;i<8 ;i++) type[(X0*8)+i][Y0*8] = WATER;
  721. X}
  722. X
  723. X/* ALLOCATE POPULATIONS OF THE WORLD*/
  724. Xpopulate()
  725. X{
  726. X    int i=0,x=0,y=0,j=0;
  727. X    int nvynum=0,army2num=0,armynum=0;
  728. X    int temp;
  729. X    int cnum=0;
  730. X    FILE *fp, *fopen();
  731. X    int done=0;
  732. X    char line[80];
  733. X
  734. X
  735. X    /*randomly scatter lizard city (want in DESERTS/swamp/Ice) */
  736. X    /*don't reproduce. Their cities are fortified and stockpiled */
  737. X#ifdef LZARD 
  738. X    strncpy(ntn[NLIZARD].name,"lizard",10);
  739. X    strncpy(ntn[NLIZARD].leader,"dragon",10);
  740. X    strcpy(ntn[NLIZARD].passwd,ntn[0].passwd);
  741. X    ntn[NLIZARD].race=LIZARD;
  742. X    ntn[NLIZARD].mark='*';
  743. X    ntn[NLIZARD].active=2;
  744. X    ntn[NLIZARD].aplus=0;
  745. X    ntn[NLIZARD].dplus=0;
  746. X    ntn[NLIZARD].maxmove=0;
  747. X    ntn[NLIZARD].repro=0;
  748. X    ntn[NLIZARD].powers=KNOWALL;
  749. X    for(i=0;i<NTOTAL;i++) if(i!=NLIZARD) {
  750. X        ntn[NLIZARD].dstatus[i]=WAR;
  751. X        ntn[i].dstatus[NLIZARD]=WAR;
  752. X    }
  753. X
  754. X    armynum=0;
  755. X    country=NLIZARD;
  756. X    while(armynum<MAXARM-2){
  757. X        x = (rand()%MAPX);
  758. X        y = (rand()%MAPY);
  759. X        if (is_habitable(x,y)) {
  760. X            sct[x][y].designation = DCASTLE;
  761. X            sct[x][y].fortress = 5+rand()%5;
  762. X            sct[x][y].gold = 15+rand()%20;
  763. X            for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  764. X                if(i>=0&&j>=0&&i<MAPX&&j<MAPX)
  765. X                    if(sct[i][j].altitude!=WATER)
  766. X                        sct[i][j].owner = NLIZARD;
  767. X            AMOVE=0;
  768. X            AXLOC=x;
  769. X            AYLOC=y;
  770. X            ASTAT=GARRISON;
  771. X            ASOLD=750+100*rand()%10;
  772. X            armynum++;
  773. X            AMOVE=8;
  774. X            AXLOC=x;
  775. X            AYLOC=y;
  776. X            ASTAT=ATTACK;
  777. X            ASOLD=750+100*rand()%10;
  778. X            armynum++;
  779. X        }
  780. X    }
  781. X    printf("%d lizards placed\n",armynum/2);
  782. X#endif
  783. X
  784. X    /* Place Brigands, Barbarians, and Nomads*/
  785. X#ifdef MONSTER 
  786. X    armynum=0;
  787. X    army2num=0;
  788. X    strcpy(ntn[NBARBARIAN].name,"bbarian");
  789. X    strcpy(ntn[NBARBARIAN].leader,"shaman");
  790. X    strcpy(ntn[NBARBARIAN].passwd,ntn[0].passwd);
  791. X    ntn[NBARBARIAN].race=BARBARIAN;
  792. X    ntn[NBARBARIAN].powers=KNOWALL;
  793. X    ntn[NBARBARIAN].mark='*';
  794. X    ntn[NBARBARIAN].active=2;
  795. X    ntn[NBARBARIAN].aplus=0;
  796. X    ntn[NBARBARIAN].dplus=10;
  797. X    ntn[NBARBARIAN].maxmove=4;
  798. X    ntn[NBARBARIAN].repro=5;
  799. X    for(i=0;i<NTOTAL;i++) if(i!=NBARBARIAN) {
  800. X        ntn[NBARBARIAN].dstatus[i]=WAR;
  801. X        ntn[i].dstatus[NBARBARIAN]=WAR;
  802. X    }
  803. X    ntn[NBARBARIAN].dstatus[NBARBARIAN]=NEUTRAL;
  804. X
  805. X    strcpy(ntn[NNOMAD].name,"nomad");
  806. X    strcpy(ntn[NNOMAD].leader,"khan");
  807. X    strcpy(ntn[NNOMAD].passwd,ntn[0].passwd);
  808. X    ntn[NNOMAD].powers=KNOWALL;
  809. X    ntn[NNOMAD].race=NOMAD;
  810. X    ntn[NNOMAD].mark='*';
  811. X    ntn[NNOMAD].active=2;
  812. X    ntn[NNOMAD].aplus=10;
  813. X    ntn[NNOMAD].dplus=0;
  814. X    ntn[NNOMAD].maxmove=4;
  815. X    ntn[NNOMAD].repro=5;
  816. X    for(i=0;i<NTOTAL;i++) if(i!=NNOMAD) {
  817. X        ntn[NNOMAD].dstatus[i]=WAR;
  818. X        ntn[i].dstatus[NNOMAD]=WAR;
  819. X    }
  820. X    ntn[NNOMAD].dstatus[NNOMAD]=NEUTRAL;
  821. X
  822. X    strcpy(ntn[NPIRATE].name,"pirate");
  823. X    strcpy(ntn[NPIRATE].leader,"captain");
  824. X    strcpy(ntn[NPIRATE].passwd,ntn[0].passwd);
  825. X    ntn[NPIRATE].powers=KNOWALL;
  826. X    ntn[NPIRATE].race=PIRATE;
  827. X    ntn[NPIRATE].mark='*';
  828. X    ntn[NPIRATE].active=2;
  829. X    ntn[NPIRATE].aplus=20;
  830. X    ntn[NPIRATE].dplus=0;
  831. X    ntn[NPIRATE].maxmove=4;
  832. X    ntn[NPIRATE].repro=5;
  833. X    for(i=0;i<NTOTAL;i++) if(i!=NPIRATE) {
  834. X        ntn[NPIRATE].dstatus[i]=WAR;
  835. X        ntn[i].dstatus[NPIRATE]=WAR;
  836. X    }
  837. X    ntn[NPIRATE].dstatus[NPIRATE]=NEUTRAL;
  838. X
  839. X    temp=(rand()%10+1)*(rand()%10+1);
  840. X    for(i=0;i<temp;i++){
  841. X        /*50% chance will be on edge, else anywhere*/
  842. X        if(rand()%2==0){
  843. X            if(rand()%2==0) {
  844. X                x=(rand()%20);
  845. X                y=(rand()%20);
  846. X            }
  847. X            else {
  848. X                x=(MAPX-(rand()%20)-1);
  849. X                y=(MAPY-(rand()%20)-1);
  850. X            }
  851. X            if(rand()%2==0) x = rand()%MAPX;
  852. X            else y = rand()%MAPY;
  853. X        }
  854. X        else {
  855. X            x = rand()%MAPX;
  856. X            y = rand()%MAPY;
  857. X        }
  858. X
  859. X        /* now place people*/
  860. X        if (is_habitable(x,y)) {
  861. X            if(rand()%2==0) {
  862. X                sct[x][y].owner = NBARBARIAN;
  863. X                country=NBARBARIAN;
  864. X                AXLOC=x;
  865. X                AYLOC=y;
  866. X                ASTAT=ATTACK;
  867. X                ASOLD=200+100*rand()%10;
  868. X                if(armynum<MAXARM-1) armynum++;
  869. X            }
  870. X            else {
  871. X                sct[x][y].owner = NNOMAD;
  872. X                ntn[NNOMAD].arm[army2num].xloc=x;
  873. X                ntn[NNOMAD].arm[army2num].yloc=y;
  874. X                ntn[NNOMAD].arm[army2num].stat=ATTACK;
  875. X                ntn[NNOMAD].arm[army2num].sold=100+100*rand()%15;
  876. X                if(army2num<MAXARM-1) army2num++;
  877. X            }
  878. X        }
  879. X        else if(nvynum<MAXNAVY) {
  880. X            country=NPIRATE;
  881. X            NXLOC=x;
  882. X            NYLOC=y;
  883. X            NWAR=2*(1+rand()%10);
  884. X            nvynum++;
  885. X        }
  886. X    }
  887. X    printf("all random population placed\n");
  888. X#endif
  889. X
  890. X    /*set up god but dont place*/
  891. X    strcpy(ntn[0].name,"unowned");
  892. X    strcpy(ntn[0].leader,"god");
  893. X    ntn[cnum].race=GOD;
  894. X    ntn[cnum].mark='-';
  895. X    ntn[cnum].active=0;
  896. X    ntn[cnum].location=GOD;
  897. X    ntn[cnum].powers=KNOWALL;
  898. X    cnum++;
  899. X
  900. X    if ((fp=fopen(helpfile,"r"))==NULL) {
  901. X        printf("\terror on read of %s file\n",helpfile);
  902. X        printf("\tdo you wish to use default help file (y or n)?");
  903. X        if(getchar()=='y'){
  904. X        sprintf(line,"cp %s/%s %s",DEFAULTDIR,helpfile,helpfile);
  905. X        printf("\n%s\n",line);
  906. X        system(line);
  907. X        } else {
  908. X            printf("\nOK; no NPC nations used\n");
  909. X            return;
  910. X        }
  911. X        getchar();
  912. X    }
  913. X
  914. X#ifdef NPC
  915. X
  916. X    /*open npcsfile file*/
  917. X    if ((fp=fopen(npcsfile,"r"))==NULL) {
  918. X        printf("error on read of %s file\n",npcsfile);
  919. X        printf("do you wish to use default NPC nations file (y or n)?");
  920. X        if(getchar()=='y'){
  921. X        sprintf(line,"%s/%s",DEFAULTDIR,npcsfile);
  922. X        if ((fp=fopen(line,"r"))==NULL) {
  923. X            printf("\nsorry; error on read of %s file\n",line);
  924. X            return;
  925. X        } else printf("\nOK; default nations used\n");
  926. X        } else {
  927. X            printf("\nOK; no NPC nations used\n");
  928. X            return;
  929. X        }
  930. X    }
  931. X    else printf("reading npc nation data from file: %s\n",npcsfile);
  932. X
  933. X    /*set up npc nation*/
  934. X    if(fgets(line,80,fp)==NULL) done=1;
  935. X      while(done==0) {
  936. X          /*read and parse a new line*/
  937. X          if(line[0]!='#') {
  938. X              sscanf(line,"%s %s %c %c %c %hd %hd %hd %ld %ld %ld %hd %hd",
  939. X             ntn[cnum].name,ntn[cnum].leader,&ntn[cnum].race,
  940. X              &ntn[cnum].mark,&ntn[cnum].location,&ntn[cnum].aplus,
  941. X              &ntn[cnum].dplus,&ntn[cnum].maxmove,&ntn[cnum].tgold,
  942. X              &ntn[cnum].tmil,&ntn[cnum].tciv,&ntn[cnum].repro,
  943. X              &ntn[cnum].active);
  944. X              ntn[cnum].active++;
  945. X              ntn[cnum].class=0;
  946. X              strcpy(ntn[cnum].passwd,ntn[0].passwd);
  947. X            country=cnum;
  948. X            if(ntn[country].race==HUMAN){
  949. X                ntn[country].powers=WARRIOR;
  950. X                exenewmgk(WARRIOR);
  951. X            }
  952. X            else if(ntn[country].race==DWARF){
  953. X                ntn[country].powers=MINER;
  954. X                exenewmgk(MINER);
  955. X            }
  956. X            else if(ntn[country].race==ELF){
  957. X                ntn[country].powers=THE_VOID;
  958. X                exenewmgk(THE_VOID);
  959. X            }
  960. X            else if(ntn[country].race==ORC){
  961. X                ntn[country].powers=MI_MONST;
  962. X                exenewmgk(MI_MONST);
  963. X            }
  964. X            else ntn[country].powers=WARRIOR;
  965. X            ntn[country].tfood=24000L;
  966. X            ntn[country].tiron=10000L;
  967. X            ntn[country].jewels=10000L;
  968. X            printf("\tnation %d: %s",cnum,line);
  969. X            cnum++;
  970. X            place();
  971. X        }
  972. X        if(fgets(line,80,fp)==NULL) done=1;
  973. X    }
  974. X    printf("all npc nations placed\n");
  975. X#endif
  976. X}
  977. END_OF_makeworld.c
  978. if test 21365 -ne `wc -c <makeworld.c`; then
  979.     echo shar: \"makeworld.c\" unpacked with wrong size!
  980. fi
  981. # end of overwriting check
  982. fi
  983. if test -f npc.c -a "${1}" != "-c" ; then 
  984.   echo shar: Will not over-write existing file \"npc.c\"
  985. else
  986. echo shar: Extracting \"npc.c\" \(24352 characters\)
  987. sed "s/^X//" >npc.c <<'END_OF_npc.c'
  988. X/*conquer is copyrighted 1986 by Ed Barlow.
  989. X *  I spent a long time writing this code & I hope that you respect this.  
  990. X *  I give permission to alter the code, but not to copy or redistribute
  991. X *  it without my explicit permission.  If you alter the code, 
  992. X *  please document changes and send me a copy, so all can have it.  
  993. X *  This code, to the best of my knowledge works well,  but it is my first
  994. X *  'C' program and should be treated as such.  I disclaim any
  995. X *  responsibility for the codes actions (use at your own risk).  I guess
  996. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  997. X *                                                Ed
  998. X */
  999. X
  1000. X#include "header.h"
  1001. X#include "data.h"
  1002. X#include <ctype.h>
  1003. X
  1004. Xextern FILE *fnews;
  1005. X
  1006. Xextern short country;
  1007. Xextern int attr[MAPX][MAPY];     /*sector attactiveness*/
  1008. Xextern short movecost[MAPX][MAPY];
  1009. Xint peace;       /*is 8 if at peace, 12 if at war*/
  1010. X
  1011. X#ifdef NPC
  1012. Xnationrun()
  1013. X{
  1014. X    int armynum,price;
  1015. X    int x,y,i,z;
  1016. X
  1017. X    prep();
  1018. X
  1019. X    /* is there an error*/
  1020. X    if((sct[ntn[country].capx][ntn[country].capy].owner==country)
  1021. X    &&(sct[ntn[country].capx][ntn[country].capy].designation!=DCAPITOL)){
  1022. X        sct[ntn[country].capx][ntn[country].capy].designation=DCAPITOL;
  1023. X    }
  1024. X
  1025. X    /*go to war*/
  1026. X    for(x=1;x<MAXNTN;x++) {
  1027. X        /*if they at war with you go to war with them*/
  1028. X        if(ntn[x].dstatus[country]>=WAR) {
  1029. X            ntn[country].dstatus[x]=WAR;
  1030. X        }
  1031. X        /*else adjust diplomacy*/
  1032. X        else if((ntn[country].dstatus[x]!=UNMET)
  1033. X        &&(ntn[country].dstatus[x]!=JIHAD)
  1034. X        &&(ntn[country].dstatus[x]!=CONFEDERACY)
  1035. X        &&(ntn[country].active!=1)){
  1036. X            if((ntn[x].tmil>4*ntn[country].tmil)
  1037. X            &&(ntn[x].score>4*ntn[country].score)){
  1038. X                if(rand()%3==0)  ntn[country].dstatus[x]=WAR;
  1039. X                else if(rand()%8==0)  
  1040. X                    ntn[country].dstatus[x]=JIHAD;
  1041. X            }
  1042. X            /*if 2* mil and 2* score then not like them*/
  1043. X            else if((ntn[x].tmil>2*ntn[country].tmil)
  1044. X            &&(ntn[x].score>2*ntn[country].score)){
  1045. X                if((ntn[country].dstatus[x]!=WAR)
  1046. X                &&(ntn[x].race!=ntn[country].race)){
  1047. X                    if(rand()%3==0) 
  1048. X                        ntn[country].dstatus[x]++;
  1049. X                }
  1050. X            }
  1051. X            /*adjust based on your status with them*/
  1052. X            if((ntn[country].dstatus[x]==WAR)
  1053. X            &&(ntn[x].dstatus[country]<WAR))
  1054. X                if(rand()%3==0) ntn[country].dstatus[x]--;
  1055. X
  1056. X            if((ntn[country].dstatus[x]<WAR)
  1057. X            &&(ntn[country].dstatus[x]>ALLIED)){
  1058. X                if(ntn[x].dstatus[country]>1+ntn[country].dstatus[x]){
  1059. X                    if(rand()%3==0) 
  1060. X                        ntn[country].dstatus[x]++;
  1061. X                }
  1062. X                else 
  1063. X                if(ntn[x].dstatus[country]+1<ntn[country].dstatus[x]){
  1064. X                    if(rand()%3==0) 
  1065. X                        ntn[country].dstatus[x]--;
  1066. X                }
  1067. X                if(ntn[x].race==ntn[country].race)
  1068. X                    if(rand()%3==0) 
  1069. X                        ntn[country].dstatus[x]--;
  1070. X            }
  1071. X            if(rand()%6==0) {
  1072. X                if(ntn[country].dstatus[x]!=JIHAD)
  1073. X                    ntn[country].dstatus[x]++;
  1074. X            }
  1075. X            else if((rand()%5==0)
  1076. X            &&(ntn[country].dstatus[x]!=CONFEDERACY)) {
  1077. X                ntn[country].dstatus[x]--;
  1078. X            }
  1079. X        }
  1080. X    }
  1081. X
  1082. X    /*move units */
  1083. X    /*are they at war with any normal countries*/
  1084. X    peace=0;
  1085. X    for(i=1;i<MAXNTN;i++) if(ntn[country].dstatus[i]>peace)
  1086. X        peace=ntn[country].dstatus[i];
  1087. X
  1088. X    if(peace<WAR){
  1089. X        peace=8;
  1090. X        pceattr();
  1091. X        for(armynum=1;armynum<MAXARM;armynum++)
  1092. X            if((ASOLD!=0)&&(ASTAT!=GARRISON)) armymove(armynum);
  1093. X    }
  1094. X    /*if war then attack &/or expand */
  1095. X    else {
  1096. X        peace=12;
  1097. X        /*are they attacking or defending */
  1098. X        for(x=0;x<MAXNTN;x++) if(ntn[country].dstatus[x]>HOSTILE){
  1099. X            if(100*(ntn[country].tmil*(ntn[country].aplus+100))/((ntn[country].tmil*(ntn[country].aplus+100))+(ntn[x].tmil*(ntn[x].dplus+100)))>rand()%100){
  1100. X                /*attacker*/
  1101. X                for(armynum=1;armynum<MAXARM;armynum++)
  1102. X                    if((ASOLD>0)&&(ASTAT!=GARRISON)) 
  1103. X                        ASTAT=ATTACK;
  1104. X                atkattr();
  1105. X            }
  1106. X            /*defender*/
  1107. X            else {
  1108. X                for(armynum=1;armynum<MAXARM;armynum++)
  1109. X                    if((ASOLD>0)&&(ASTAT!=GARRISON)){
  1110. X                        if(ASOLD<350) ASTAT=DEFEND;
  1111. X                        else ASTAT=ATTACK;
  1112. X                    }
  1113. X                defattr();
  1114. X            }
  1115. X        }
  1116. X
  1117. X        for(armynum=1;armynum<MAXARM;armynum++)
  1118. X            if((ASOLD!=0)&&(ASTAT!=GARRISON)) armymove(armynum);
  1119. X    }
  1120. X
  1121. X    /*redesignate sectors*/
  1122. X    if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1123. X        if((sct[x][y].owner==country)
  1124. X            &&(is_habitable(x,y))) npcredes(x,y);
  1125. X    if(ntn[country].active==1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1126. X        if((sct[x][y].owner==country)
  1127. X            &&((sct[x][y].designation)!=DCITY) 
  1128. X            &&((sct[x][y].designation)!=DFARM) 
  1129. X            &&((sct[x][y].designation)!=DMINE) 
  1130. X            &&((sct[x][y].designation)!=DGOLDMINE) 
  1131. X            &&((sct[x][y].designation)!=DCAPITOL)
  1132. X            &&(is_habitable(x,y)))
  1133. X                npcredes(x,y);
  1134. X
  1135. X    /*build forts in any cities*/
  1136. X    if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1137. X        if(((sct[x][y].designation==DCITY)
  1138. X            ||(sct[x][y].designation==DCAPITOL))
  1139. X            &&(sct[x][y].fortress<(sct[x][y].people%1000))
  1140. X            &&(sct[x][y].fortress<5))
  1141. X            sct[x][y].fortress++;
  1142. X
  1143. X    /*redo mil*/
  1144. X    /*rate position -- any cities with no garison get one*/
  1145. X    if(ntn[country].active!=1) redomil();
  1146. X
  1147. X    /*buy new powers and/or new weapons*/
  1148. X    price=JWL_MGK;
  1149. X    for(armynum=1; armynum<num_powers(country); armynum++ ) price <<= 1;
  1150. X
  1151. X    if(ntn[country].jewels > 2 * price) {
  1152. X        if((z=getmagic())!=0){
  1153. X            fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z);
  1154. X            exenewmgk(z);
  1155. X            ntn[country].jewels-=price;
  1156. X        }
  1157. X        else if((z=getmagic())!=0){
  1158. X            fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z);
  1159. X            exenewmgk(z);
  1160. X            ntn[country].jewels-=price;
  1161. X        }
  1162. X        else if((z=getmagic())!=0){
  1163. X            fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z);
  1164. X            exenewmgk(z);
  1165. X            ntn[country].jewels-=price;
  1166. X        }
  1167. X    }
  1168. X    i=0;
  1169. X    if(magic(country,WARLORD)==1) i=30;
  1170. X    else if(magic(country,CAPTAIN)==1) i=20;
  1171. X    else if(magic(country,WARRIOR)==1) i=10;
  1172. X    x = max ( ntn[country].aplus-i, 10 ) / 10;
  1173. X    if(ntn[country].tiron >  3 * IRONORE * ntn[country].tmil*x*x){
  1174. X        ntn[country].aplus+=1;
  1175. X        ntn[country].dplus+=1;
  1176. X        ntn[country].tiron-=2*IRONORE*ntn[country].tmil*x*x;
  1177. X    }
  1178. X}
  1179. X
  1180. X/*calculate attractiveness when at peace*/
  1181. Xpceattr()
  1182. X{
  1183. X    int x,y,temp;
  1184. X    /*add around capital*/
  1185. X    for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
  1186. X        for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
  1187. X            if((ONMAP)&&(sct[x][y].owner==0)) attr[x][y]+=180;
  1188. X
  1189. X    /*add to attractiveness for unowned sectors*/
  1190. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==0) {
  1191. X        /*temp stands for the distance from the capital*/
  1192. X        temp=0;
  1193. X        if(x>ntn[country].capx) temp+=x-ntn[country].capx;
  1194. X        else temp+=ntn[country].capx-x;
  1195. X        if(y>ntn[country].capy) temp+=y-ntn[country].capy;
  1196. X        else temp+=ntn[country].capy-y;
  1197. X        if(temp<3) attr[x][y]+=300-(50*temp);
  1198. X        else if(temp<20) attr[x][y]+=100;
  1199. X    }
  1200. X    else if((sct[x][y].owner==NNOMAD)
  1201. X    ||(sct[x][y].owner==NBARBARIAN)
  1202. X    ||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100;
  1203. X
  1204. X    if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
  1205. X        attr[ntn[country].capy][ntn[country].capy]=1000;
  1206. X    }
  1207. X}
  1208. X
  1209. X/*calculate attractiveness of attacking sectors*/
  1210. Xatkattr()
  1211. X{
  1212. X    int nation,armie,x,y,x1,x2,Y1,y2;
  1213. X
  1214. X    for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
  1215. X        for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
  1216. X            if((ONMAP)&&(sct[x][y].owner==0)) attr[x][y]+=80;
  1217. X
  1218. X    for(x=0;x<MAPX;x++) 
  1219. X        for(y=0;y<MAPY;y++) 
  1220. X            if((sct[x][y].owner==0)
  1221. X            ||(sct[x][y].owner==NNOMAD)
  1222. X            ||(sct[x][y].owner==NBARBARIAN)
  1223. X            ||(sct[x][y].owner==NPIRATE)) 
  1224. X                attr[x][y]+=100;
  1225. X
  1226. X    /*adjust for each nation that you are at war with*/
  1227. X    for(nation=1;nation<MAXNTN;nation++) 
  1228. X    if((ntn[country].dstatus[nation]>=WAR)&&(ntn[country].active!=0)){
  1229. X
  1230. X        /*plus 1/2 men if in sector with their army*/
  1231. X        /*defend your capital if occupied, +50 more if with their army*/
  1232. X        for(armie=1;armie<MAXARM;armie++){
  1233. X            if(ntn[nation].arm[armie].sold > 0) {
  1234. X
  1235. X                attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/10;
  1236. X
  1237. X            if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2)
  1238. X            &&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2)
  1239. X            &&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2)
  1240. X            &&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){
  1241. X                attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5;
  1242. X                if((rand()%3==0)
  1243. X                &&(ntn[country].dstatus[nation]<WAR))
  1244. X                    ntn[country].dstatus[nation]++;
  1245. X            if((ntn[nation].arm[armie].xloc==ntn[country].capx)
  1246. X            &&(ntn[nation].arm[armie].yloc==ntn[country].capy)){
  1247. X                    if(ntn[country].dstatus[nation]==WAR)
  1248. X                    ntn[country].dstatus[nation]=JIHAD;
  1249. X                    if(ntn[nation].arm[armie].sold>2*ntn[country].arm[0].sold){
  1250. X                        attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/2;
  1251. X                    }
  1252. X                    else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5;
  1253. X                }
  1254. X                }
  1255. X            }
  1256. X        }
  1257. X
  1258. X        /*plus 40 if next to their capital */
  1259. X        for(x=ntn[nation].capx-1;x<=ntn[nation].capy+1;x++){
  1260. X            for(y=ntn[nation].capy-1;y<=ntn[nation].capy+1;y++){
  1261. X                if(ONMAP)
  1262. X                attr[x][y]+=40;
  1263. X            }
  1264. X        }
  1265. X
  1266. X        /*plus 100 if on their capital*/
  1267. X        attr[ntn[nation].capx][ntn[nation].capy]+=100;
  1268. X
  1269. X        /*+60 if between the two capitals*/
  1270. X        if (ntn[nation].capx < ntn[country].capx){
  1271. X            x1=ntn[nation].capx;
  1272. X            x2=ntn[country].capx;
  1273. X        }
  1274. X        else {
  1275. X            x1=ntn[country].capx;
  1276. X            x2=ntn[nation].capx;
  1277. X        }
  1278. X        if (ntn[nation].capy < ntn[country].capy){
  1279. X            Y1=ntn[nation].capy;
  1280. X            y2=ntn[country].capy;
  1281. X        }
  1282. X        else {
  1283. X            Y1=ntn[country].capy;
  1284. X            y2=ntn[nation].capy;
  1285. X        }
  1286. X        for(x=x1;x<=x2;x++) for(y=Y1;y<=y2;y++) {
  1287. X            if(ONMAP) attr[x][y]+=60;
  1288. X        }
  1289. X
  1290. X        /*for each sector +60 if their sector*/
  1291. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1292. X            if((sct[x][y].owner==nation)&&(occ[x][y]==0))
  1293. X                attr[x][y]+=100;
  1294. X            else if(sct[x][y].owner==nation) 
  1295. X                attr[x][y]+=60;
  1296. X    }
  1297. X    if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
  1298. X        attr[ntn[country].capy][ntn[country].capy]=1000;
  1299. X    }
  1300. X}
  1301. X
  1302. Xdefattr()
  1303. X{
  1304. X    int nation,armie,x,y,x1,x2,y1,y2;
  1305. X
  1306. X    for(x=0;x<MAPX;x++) 
  1307. X        for(y=0;y<MAPY;y++) 
  1308. X            if((sct[x][y].owner==0)
  1309. X            ||(sct[x][y].owner==NNOMAD)
  1310. X            ||(sct[x][y].owner==NBARBARIAN)
  1311. X            ||(sct[x][y].owner==NPIRATE)) 
  1312. X                attr[x][y]+=100;
  1313. X
  1314. X    for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
  1315. X        for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
  1316. X            if(ONMAP&&(sct[x][y].owner==0)) attr[x][y]+=80;
  1317. X
  1318. X    for(nation=1;nation<MAXNTN;nation++) 
  1319. X    if((ntn[nation].active!=0)&&(ntn[country].dstatus[nation]>=WAR)) {
  1320. X
  1321. X        /*plus if near enemy army*/
  1322. X        /*plus 30 if next to their army*/
  1323. X        /*plus 60 if with their army*/
  1324. X        for(armie=1;armie<MAXARM;armie++) 
  1325. X        if(ntn[nation].arm[armie].sold > 0) {
  1326. X
  1327. X            attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/10;
  1328. X
  1329. X            if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2)
  1330. X            &&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2)
  1331. X            &&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2)
  1332. X            &&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){
  1333. X                attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5;
  1334. X                if((rand()%3==0)
  1335. X                &&(ntn[country].dstatus[nation]<WAR))
  1336. X                    ntn[country].dstatus[nation]++;
  1337. X                if((ntn[nation].arm[armie].xloc==ntn[country].capx)
  1338. X                &&(ntn[nation].arm[armie].yloc==ntn[country].capy)){
  1339. X                    if(ntn[country].dstatus[nation]==WAR)
  1340. X                    ntn[country].dstatus[nation]=JIHAD;
  1341. X                    if(ntn[nation].arm[armie].sold>2*ntn[country].arm[0].sold){
  1342. X                        attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/2;
  1343. X                    }
  1344. X                    else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5;
  1345. X                }
  1346. X            }
  1347. X        }
  1348. X
  1349. X
  1350. X        /*plus if strategic blocking sector*/
  1351. X        /*+60 if between the two capitals*/
  1352. X        if (ntn[nation].capx < ntn[country].capx){
  1353. X            x1=ntn[nation].capx;
  1354. X            x2=ntn[country].capx;
  1355. X        }
  1356. X        else {
  1357. X            x1=ntn[country].capx;
  1358. X            x2=ntn[nation].capx;
  1359. X        }
  1360. X        if (ntn[nation].capy < ntn[country].capy){
  1361. X            y1=ntn[nation].capy;
  1362. X            y2=ntn[country].capy;
  1363. X        }
  1364. X        else {
  1365. X            y1=ntn[country].capy;
  1366. X            y2=ntn[nation].capy;
  1367. X        }
  1368. X
  1369. X        for(x=x1;x<=x2;x++) for(y=y1;y<=y2;y++) {
  1370. X            if(ONMAP) attr[x][y]+=60;
  1371. X        }
  1372. X
  1373. X        /*plus 80 if near your capital */
  1374. X        for(x=ntn[country].capx-1;x<=ntn[country].capy+1;x++){
  1375. X            for(y=ntn[country].capy-1;y<=ntn[country].capy+1;y++){
  1376. X                if(ONMAP) attr[x][y]+=80;
  1377. X            }
  1378. X        }
  1379. X
  1380. X        /*plus based on defensive value*/
  1381. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
  1382. X            if(movecost[x][y]==1) attr[x][y] += 50;
  1383. X            else if(movecost[x][y]<=3) attr[x][y] += 20;
  1384. X            else if(movecost[x][y]<=5) attr[x][y] += 10;
  1385. X
  1386. X            if((sct[x][y].designation==DCITY)
  1387. X            &&((sct[x][y].owner==country)
  1388. X            ||(sct[x][y].owner==nation))){
  1389. X                attr[x][y] += 50;
  1390. X            }
  1391. X
  1392. X            /* plus 60 if they own and unoccupied*/
  1393. X            if((sct[x][y].owner==nation)&&(occ[x][y]==0)) 
  1394. X                attr[x][y]+=100;
  1395. X            else if(sct[x][y].owner==nation) attr[x][y]+=60;
  1396. X        }
  1397. X    }
  1398. X
  1399. X    if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
  1400. X        attr[ntn[country].capy][ntn[country].capy]=1000;
  1401. X    }
  1402. X}
  1403. X#endif
  1404. X
  1405. X/*ntn 1 is nation you are updating*/
  1406. Xnewdip(ntn1,ntn2)
  1407. X{
  1408. X    if(ntn[ntn1].active<2) {
  1409. X        if(ntn[ntn1].dstatus[ntn2]==UNMET)
  1410. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1411. X    }
  1412. X    else if(ntn[ntn1].race==ntn[ntn2].race){
  1413. X        if(rand()%5<3) ntn[ntn1].dstatus[ntn2]=FRIENDLY;
  1414. X        else if(rand()%2==0) ntn[ntn1].dstatus[ntn2]=ALLIED;
  1415. X        else ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1416. X    }
  1417. X    else switch(ntn[ntn1].race) {
  1418. X    case DWARF:
  1419. X        switch(ntn[ntn2].race) {
  1420. X        case ELF:
  1421. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  1422. X            break;
  1423. X        case HUMAN:
  1424. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1425. X            break;
  1426. X        case ORC:
  1427. X        default:
  1428. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1429. X            break;
  1430. X        }
  1431. X        break;
  1432. X    case ELF:
  1433. X        switch(ntn[ntn2].race) {
  1434. X        case DWARF:
  1435. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  1436. X            break;
  1437. X        case HUMAN:
  1438. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1439. X            break;
  1440. X        case ORC:
  1441. X        default:
  1442. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1443. X            break;
  1444. X        }
  1445. X        break;
  1446. X    case ORC:
  1447. X        switch(ntn[ntn2].race) {
  1448. X        case HUMAN:
  1449. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1450. X            break;
  1451. X        case DWARF:
  1452. X        case ELF:
  1453. X        default:
  1454. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1455. X            break;
  1456. X        }
  1457. X        break;
  1458. X    case HUMAN:
  1459. X        switch(ntn[ntn2].race) {
  1460. X        case DWARF:
  1461. X        case ELF:
  1462. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1463. X            break;
  1464. X        case ORC:
  1465. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  1466. X            break;
  1467. X        default:
  1468. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1469. X            break;
  1470. X        }
  1471. X        break;
  1472. X    default:
  1473. X        ntn[ntn1].dstatus[ntn2]=WAR;
  1474. X        break;
  1475. X    }
  1476. X}
  1477. X
  1478. X/*destroy nation--special case if capital not owned by other nation*/
  1479. Xdestroy()
  1480. X{
  1481. X    short armynum, nvynum;
  1482. X    int i, x, y;
  1483. X    fprintf(fnews,"1.\tDESTROY NATION %s",ntn[country].name);
  1484. X    if(country!=sct[ntn[country].capx][ntn[country].capy].owner){
  1485. X        fprintf(fnews,"\t(their capitol is owned by %s)\n",ntn[sct[ntn[country].capx][ntn[country].capy].owner].name);
  1486. X        /*get +5% to combat skill*/
  1487. X        ntn[sct[ntn[country].capx][ntn[country].capy].owner].aplus+=5;
  1488. X    }
  1489. X    else fprintf(fnews,"\t(they own their capitol)\n");
  1490. X
  1491. X    ntn[country].active=0;
  1492. X    for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0) {
  1493. X        if(ntn[sct[AXLOC][AYLOC].owner].race==ntn[country].race)
  1494. X            sct[AXLOC][AYLOC].people+=ASOLD;
  1495. X        ASOLD=0;
  1496. X    }
  1497. X    for(nvynum=0;nvynum<MAXNAVY;nvynum++) {
  1498. X        NMER=0;
  1499. X        NWAR=0;
  1500. X    }
  1501. X    for(i=0;i<MAXNTN;i++) {
  1502. X        ntn[i].dstatus[country]=UNMET;
  1503. X        ntn[country].dstatus[i]=UNMET;
  1504. X    }
  1505. X
  1506. X    /*if take them you get their gold*/
  1507. X    if(country!=sct[ntn[country].capx][ntn[country].capy].owner){
  1508. X        if(ntn[country].tgold>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tgold+=ntn[country].tgold;
  1509. X        if(ntn[country].jewels>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].jewels+=ntn[country].jewels;
  1510. X        if(ntn[country].tiron>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tiron+=ntn[country].tiron;
  1511. X        if(ntn[country].tfood>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tfood+=ntn[country].tfood;
  1512. X    }
  1513. X
  1514. X    /*if god destroys then kill all population*/
  1515. X    if(country==sct[ntn[country].capx][ntn[country].capy].owner){
  1516. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) 
  1517. X        if(sct[x][y].owner==country) {
  1518. X            sct[x][y].people=0;
  1519. X            sct[x][y].owner=0;
  1520. X            if(isdigit(sct[x][y].vegetation)!=0)
  1521. X                sct[x][y].designation=DNODESIG;
  1522. X        }
  1523. X    }
  1524. X    /*slowly take over and all people flee*/
  1525. X    else if(ntn[sct[ntn[country].capx][ntn[country].capy].owner].race!=ntn[country].race){
  1526. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) 
  1527. X        if(sct[x][y].owner==country) {
  1528. X            /*all kinds of refugees to neighboring countries*/
  1529. X            flee(x,y,1);
  1530. X            sct[x][y].people=0;
  1531. X            sct[x][y].owner=0;
  1532. X            if(isdigit(sct[x][y].vegetation)!=0)
  1533. X                sct[x][y].designation=DNODESIG;
  1534. X        }
  1535. X    }
  1536. X    /*else same race, so give all land to conqueror*/
  1537. X    else {
  1538. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) 
  1539. X        if(sct[x][y].owner==country){
  1540. X            sct[x][y].owner=sct[ntn[country].capx][ntn[country].capy].owner;
  1541. X            if(isdigit(sct[x][y].vegetation)!=0)
  1542. X                sct[x][y].designation=DNODESIG;
  1543. X        }
  1544. X    }
  1545. X    return;
  1546. X}
  1547. X
  1548. Xmonster()
  1549. X{
  1550. X    short nvynum,armynum;
  1551. X    int x, y;
  1552. X
  1553. X    /*move nomads randomly until within 2 of city then attack*/
  1554. X    country=NNOMAD;
  1555. X    for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0){
  1556. X        x=AXLOC+rand()%4-2;
  1557. X        y=AYLOC+rand()%4-2;
  1558. X        if(ONMAP&&(is_habitable(x,y)) 
  1559. X        &&(land_reachp(AXLOC,AYLOC,x,y,ntn[country].arm[armynum].smove,country))){
  1560. X            AXLOC=x;
  1561. X            AYLOC=y;
  1562. X            /*if owned & unoccupied you take & people flee*/
  1563. X            if( (sct[x][y].owner) == 0 || solds_in_sector( x, y, sct[x][y].owner) == 0 ) {
  1564. X                if(sct[x][y].owner==0)
  1565. X                    fprintf(fnews,"3.\tnomads take sector %d,%d\n",x,y);
  1566. X                else fprintf(fnews,"3.\tnomads capture sector %d,%d\n",x,y);
  1567. X                if(sct[x][y].owner!=0) flee(x,y,1);
  1568. X                sct[x][y].owner=NNOMAD;
  1569. X                sct[x][y].designation=DDEVASTATED;
  1570. X            }
  1571. X        }
  1572. X    }
  1573. X    else {
  1574. X        /*place a new Nomad army*/
  1575. X        x=(rand()%(MAPX-8))+4;
  1576. X        y=(rand()%(MAPY-8))+4;
  1577. X        if((rand()%4==0)&&(is_habitable(x,y))) {
  1578. X            AXLOC=x;
  1579. X            AYLOC=y;
  1580. X            ASOLD=100+100*rand()%10;
  1581. X            ASTAT=ATTACK;
  1582. X        }
  1583. X    }
  1584. X    fprintf(fnews,"2.\t%s are updated\n",ntn[NPIRATE].name);
  1585. X    /*if pirate fleet within 3 attack if outnumber any fleets */
  1586. X    for(nvynum=0;nvynum<MAXNAVY;nvynum++){
  1587. X    for(x=1;x<MAXNTN;x++) for(y=0;y<MAXNAVY;y++)
  1588. X    if((ntn[x].nvy[y].xloc-NXLOC<2)
  1589. X    &&(ntn[x].nvy[y].xloc-NXLOC>(-2))
  1590. X    &&(ntn[x].nvy[y].yloc-NYLOC<2)
  1591. X    &&(ntn[x].nvy[y].yloc-NYLOC>(-2))
  1592. X    &&(sct[ntn[x].nvy[y].xloc][ntn[x].nvy[y].yloc].altitude==WATER)){
  1593. X        NXLOC= ntn[x].nvy[y].xloc;
  1594. X        NYLOC= ntn[x].nvy[y].yloc;
  1595. X    }
  1596. X    /*add one warship to random pirate fleet*/
  1597. X    if((NWAR>0)&&(rand()%3==0)) NWAR++;
  1598. X    }
  1599. X}
  1600. X
  1601. Xnpcredes(x,y)
  1602. X{
  1603. X    long food;
  1604. X    /*large enough for a city now?*/
  1605. X    if(((sct[x][y].people*(CITYLIMIT+(ntn[sct[x][y].owner].tsctrs/3))>ntn[sct[x][y].owner].tciv)
  1606. X    ||((ntn[sct[x][y].owner].tciv<30000)
  1607. X    &&(sct[x][y].people>1000)))
  1608. X    &&(ntn[sct[x][y].owner].tfood>ntn[sct[x][y].owner].tciv*2)){
  1609. X        if((rand()%2==0)
  1610. X        &&((sct[x][y].designation==DFARM)
  1611. X           ||(sct[x][y].designation==DGOLDMINE)
  1612. X           ||(sct[x][y].designation==DMINE))
  1613. X        &&(sct[x][y].iron<5)
  1614. X        &&(sct[x][y].gold<5))
  1615. X            sct[x][y].designation=DCITY;
  1616. X    }
  1617. X    /*not large enough for city and not enough food*/
  1618. X    else if((sct[x][y].designation==DCITY)
  1619. X    &&(ntn[sct[x][y].owner].tfood<ntn[sct[x][y].owner].tciv*2)
  1620. X    &&(todigit(sct[x][y].vegetation)>5)){
  1621. X        sct[x][y].designation=DFARM;
  1622. X        food= (long) todigit(sct[x][y].vegetation)*sct[x][y].people;
  1623. X        ntn[sct[x][y].owner].tfood += food;
  1624. X        ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100);
  1625. X    }
  1626. X    /*not large enough for a city but enough food*/
  1627. X    else if((sct[x][y].designation==DCITY)&&(rand()%5==0)){
  1628. X        sct[x][y].designation=DFARM;
  1629. X        food= (long) todigit(sct[x][y].vegetation)*sct[x][y].people;
  1630. X        ntn[sct[x][y].owner].tfood += food;
  1631. X        ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100);
  1632. X    }
  1633. X
  1634. X    /*what if it is not a city*/
  1635. X    if((sct[x][y].designation!=DCITY)&&(sct[x][y].designation!=DCAPITOL)){
  1636. X        sct[x][y].designation=DFARM;
  1637. X        /*crisis situation -- need more food producers*/
  1638. X        if(ntn[sct[x][y].owner].tfood<=2*ntn[sct[x][y].owner].tciv){
  1639. X            if(sct[x][y].iron>5)
  1640. X                sct[x][y].designation=DMINE;
  1641. X            if((sct[x][y].gold>5)
  1642. X            &&(sct[x][y].gold>sct[x][y].iron-2))
  1643. X                sct[x][y].designation=DGOLDMINE;
  1644. X        }
  1645. X        /*non crisis situation -- need more food producers*/
  1646. X        else {
  1647. X            if(sct[x][y].iron>2)
  1648. X                sct[x][y].designation=DMINE;
  1649. X            if((sct[x][y].gold>2)
  1650. X            &&(sct[x][y].gold>sct[x][y].iron-2))
  1651. X                sct[x][y].designation=DGOLDMINE;
  1652. X        }
  1653. X    }
  1654. X}
  1655. X
  1656. Xredomil()
  1657. X{
  1658. X    short x,y,armynum;
  1659. X    int i, free, done, ideal;
  1660. X    long diff;
  1661. X
  1662. X    /*make sure enough men in army 0 -- garrison duty in capital*/
  1663. X    armynum=0;
  1664. X    ASTAT=GARRISON;
  1665. X    AXLOC=ntn[country].capx;
  1666. X    AYLOC=ntn[country].capy;
  1667. X
  1668. X    /*Ideally ASOLD[0]*MILINCAP=tmil*peace/10*/
  1669. X    ideal = ntn[country].tmil * peace / (10*MILINCAP);
  1670. X/*if(peace==8) printf("\tpeace - incap is %d, ideal is %d,",ASOLD,ideal);
  1671. X *else if(peace==12)  printf("\twar - incap is %d, ideal is %d,",ASOLD,ideal);
  1672. X *else printf("error - incap is %d ideal is %d",ASOLD,ideal);
  1673. X */
  1674. X    /*MILRATIO ratio mil:civ for non player countries*/
  1675. X    /*MILINCAP ratio (mil in cap):mil for NPCs*/
  1676. X
  1677. X    if((ASOLD*10) < (9*ideal)){
  1678. X
  1679. X    /*too few soldiers on garrison*/
  1680. X    /*diff is number to change mil in cap (>0)*/
  1681. X    if(ntn[country].tgold<0L) diff=0;
  1682. X    else diff = (long) min ( ideal-ASOLD , (int) (ntn[country].tiron/10));
  1683. X
  1684. X    diff = (long) min ((int) diff, sct[ntn[country].capx][ntn[country].capy].people/2);
  1685. X    if(ntn[country].tgold<=0 || ntn[country].tiron<=0) if(diff > 0) diff=0;
  1686. X
  1687. X    /*printf(" add-diff is %d",diff);*/
  1688. X    sct[ntn[country].capx][ntn[country].capy].people-=diff;
  1689. X    ASOLD+=diff;
  1690. X    ntn[country].tciv-=diff;
  1691. X    ntn[country].tmil+=diff;
  1692. X    ntn[country].tgold-=diff*ENLISTCOST;
  1693. X    ntn[country].tiron-=diff*10;
  1694. X    }
  1695. X    /*else split garrison army if 1.25* needed number*/
  1696. X    else if(ASOLD *4 > 5*ideal){
  1697. X        /*diff here is a negative number*/
  1698. X        diff=((4*ASOLD)-(5*ideal))/4;
  1699. X        /*printf(" split diff is %d",diff);*/
  1700. X        free=0;
  1701. X        ASOLD-=diff;
  1702. X        ntn[country].tmil-=diff;
  1703. X        ntn[country].tciv+=diff;
  1704. X        sct[ntn[country].capx][ntn[country].capy].people+=diff;
  1705. X        /*I add back gold as armies get redone anyway*/
  1706. X        ntn[country].tiron+=diff*10;
  1707. X        ntn[country].tgold+=diff*ENLISTCOST;
  1708. X    }
  1709. X    /*else printf(" no action - diff=%d",diff);*/
  1710. X    /*printf(" new Arm 0 is %d",ASOLD);*/
  1711. X
  1712. X    /*build ships and/or armies*/
  1713. X    done=0;
  1714. X    ideal = ntn[country].tciv * peace / (10 * MILRATIO);
  1715. X    /*printf("\n\ttmil is %d ideal is %d",ntn[country].tmil,ideal);*/
  1716. X    /*if tmil*MILRATIO<tciv build new army in the capital if possible*/
  1717. X    if(ntn[country].tmil < (.8*ideal)) {
  1718. X    for(armynum=1;armynum<MAXARM;armynum++) 
  1719. X    if((done==0)&&(ASOLD==0)) {
  1720. X        done=1;
  1721. X        ASOLD = min ((int) (ideal-ntn[country].tmil), (int) (ntn[country].tiron/10));
  1722. X        ASOLD = min (ASOLD,sct[ntn[country].capx][ntn[country].capy].people/2);
  1723. X        ASOLD = min (ASOLD, (int) (ntn[country].tgold/ENLISTCOST));
  1724. X        if(ASOLD>0){
  1725. X        /*printf(" build army %d to %d men",armynum,ASOLD);*/
  1726. X        ntn[country].tiron-=ASOLD*10;
  1727. X        AXLOC= ntn[country].capx;
  1728. X        AYLOC= ntn[country].capy;
  1729. X        ntn[country].tmil += ASOLD;
  1730. X        ntn[country].tciv -= ASOLD;
  1731. X        ntn[country].tgold-=ASOLD*ENLISTCOST;
  1732. X        sct[AXLOC][AYLOC].people-=ASOLD;
  1733. X        ASTAT= DEFEND;
  1734. X        AMOVE=0;
  1735. X        }
  1736. X    }
  1737. X    }
  1738. X    /*disband ships and/or armies*/
  1739. X    else if(ntn[country].tmil > 1.2*ideal){
  1740. X        /*disband a pseudo-random army*/
  1741. X        done=0;
  1742. X        diff=ntn[country].tmil-(1.2*ideal);
  1743. X        for(armynum=1;armynum<MAXARM;armynum++)
  1744. X            if((done==0)&&(sct[AXLOC][AYLOC].owner==country)
  1745. X            &&((sct[AXLOC][AYLOC].gold>5)
  1746. X            ||(sct[AXLOC][AYLOC].iron>5))
  1747. X            &&(rand()%5==0)&&(ASOLD<diff)){
  1748. X                /*printf(" eliminate army %d",armynum);*/
  1749. X                diff-=ASOLD;
  1750. X                sct[AXLOC][AYLOC].people+=ASOLD;
  1751. X                ntn[country].tmil -= ASOLD;
  1752. X                ntn[country].tciv += ASOLD;
  1753. X                ASOLD=0;
  1754. X                if(ntn[country].tmil < 1.2*ideal) done=1;
  1755. X            }
  1756. X    }
  1757. X    /*printf(" new tmil is %d\n",ntn[country].tmil);*/
  1758. X
  1759. X    /*resize armies */
  1760. X    /*maximum npc army is 200 or tmil/20, minimum is 50*/
  1761. X    for(armynum=1;armynum<MAXARM;armynum++){
  1762. X        if((ASOLD>200)&&(ASOLD>ntn[country].tmil/20)) {
  1763. X            free=0;
  1764. X            for(i=1;i<MAXARM;i++){
  1765. X                if((free==0)&&(ntn[country].arm[i].sold==0)){
  1766. X                    free=1;
  1767. X                    ASOLD/=2;
  1768. X                    ntn[country].arm[i].sold  = ASOLD;
  1769. X                    ntn[country].arm[i].smove = AMOVE;
  1770. X                    ntn[country].arm[i].stat  = DEFEND;
  1771. X                    ntn[country].arm[i].xloc  = AXLOC;
  1772. X                    ntn[country].arm[i].yloc  = AYLOC;
  1773. X                }
  1774. X            }
  1775. X        }
  1776. X    /*minimum npc army is 50, merge them*/
  1777. X        else if(ASOLD<50) {
  1778. X            free=0;
  1779. X            for(i=1;i<MAXARM;i++){
  1780. X                if((ntn[country].arm[i].sold>0)
  1781. X                &&(ntn[country].arm[i].xloc==AXLOC)
  1782. X                &&(ntn[country].arm[i].yloc==AYLOC)
  1783. X                &&(i!=armynum)&&(free==0)){
  1784. X                    free=1;
  1785. X                    ntn[country].arm[i].sold += ASOLD;
  1786. X                    ASOLD=0;
  1787. X                }
  1788. X            }
  1789. X        }
  1790. X    }
  1791. X
  1792. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) 
  1793. X    if((sct[x][y].owner==country)&&(sct[x][y].designation==DCITY)){
  1794. X        free=0;
  1795. X        for(armynum=0;armynum<MAXARM;armynum++){
  1796. X            if((AXLOC==x)&&(AYLOC==y)) free=1;
  1797. X        }
  1798. X        /*move army in*/
  1799. X        if(free==0){
  1800. X            for(armynum=1;armynum<MAXARM;armynum++)
  1801. X                if((abs(AXLOC-x)<=1)&&(abs(AYLOC-y)<=1))
  1802. X                    free=armynum;
  1803. X            if(free>0){
  1804. X                armynum=free;
  1805. X                AXLOC=x;
  1806. X                AYLOC=y;
  1807. X            }
  1808. X        }
  1809. X    }
  1810. X}
  1811. END_OF_npc.c
  1812. if test 24352 -ne `wc -c <npc.c`; then
  1813.     echo shar: \"npc.c\" unpacked with wrong size!
  1814. fi
  1815. # end of overwriting check
  1816. fi
  1817. echo shar: End of archive 2 \(of 6\).
  1818. cp /dev/null ark2isdone
  1819. MISSING=""
  1820. for I in 1 2 3 4 5 6 ; do
  1821.     if test ! -f ark${I}isdone ; then
  1822.     MISSING="${MISSING} ${I}"
  1823.     fi
  1824. done
  1825. if test "${MISSING}" = "" ; then
  1826.     echo You have unpacked all 6 archives.
  1827.     rm -f ark[1-9]isdone
  1828. else
  1829.     echo You still need to unpack the following archives:
  1830.     echo "        " ${MISSING}
  1831. fi
  1832. ##  End of shell archive.
  1833. exit 0
  1834.